/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Yohanes Beny P
 */
public class CekStokBarangCabang {

    private String id_cab;
    private String kodebarang;
    private String namabarang;
    private String kodekategori;
    private String jmlh;

    public CekStokBarangCabang() {
    }

    public CekStokBarangCabang(String id_cab, String kodebarang, String namabarang, String kodekategori, String jmlh) {
        this.id_cab = id_cab;
        this.kodebarang = kodebarang;
        this.namabarang = namabarang;
        this.kodekategori = kodekategori;
        this.jmlh = jmlh;
    }

    public String getId_cab() {
        return id_cab;
    }

    public void setId_cab(String id_cab) {
        this.id_cab = id_cab;
    }

    public String getKodebarang() {
        return kodebarang;
    }

    public void setKodebarang(String kodebarang) {
        this.kodebarang = kodebarang;
    }

    public String getNamabarang() {
        return namabarang;
    }

    public void setNamabarang(String namabarang) {
        this.namabarang = namabarang;
    }

    public String getKodekategori() {
        return kodekategori;
    }

    public void setKodekategori(String kodekategori) {
        this.kodekategori = kodekategori;
    }

    public String getJmlh() {
        return jmlh;
    }

    public void setJmlh(String jmlh) {
        this.jmlh = jmlh;
    }

    public String tampilNamaCabang(String id) throws SQLException {
        String nama = null;
        Connection con = DataBase.Koneksi.open();
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("select NAMA_CABANG from CABANG_FROGSTONE where ID_CABANG='" + id + "'");
        while (rs.next()) {
            nama = rs.getString("NAMA_CABANG");
        }
        return nama;
    }

    public ResultSet tampilStokCabang(String idcabang) {
        Connection con = DataBase.Koneksi.open();
        Statement stat = null;
        try {
            stat = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(CekStokBarangPusat.class.getName()).log(Level.SEVERE, null, ex);
        }
        String que1 = "select * from STOCKBARANGCABANG_FROGSTONE where id_cabang='"+idcabang+"'";
        ResultSet res = null;
        try {
            res = stat.executeQuery(que1);
        } catch (SQLException ex) {
            Logger.getLogger(CekStokBarangPusat.class.getName()).log(Level.SEVERE, null, ex);
        }
        return res;
    }

    public void tambahStokCabang() {
        Connection con = DataBase.Koneksi.open();
        Statement st = null;
        try {
            st = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(CekStokBarangCabang.class.getName()).log(Level.SEVERE, null, ex);
        }
        String ins = "insert into STOCKBARANGCABANG_FROGSTONE "
                + "values ('" + getId_cab() + "','" + getKodebarang() + "','" + getNamabarang()
                + "','" + getKodekategori() + "','" + getJmlh() + "')";
        try {
            st.executeQuery(ins);
        } catch (SQLException ex) {
            Logger.getLogger(CekStokBarangCabang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public ResultSet cekKodeBarang(String idcabang) {
        Connection con = DataBase.Koneksi.open();
        Statement stat = null;
        try {
            stat = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(CekStokBarangCabang.class.getName()).log(Level.SEVERE, null, ex);
        }
        String que1 = "select * from STOCKBARANGCABANG_FROGSTONE where id_cabang='" + idcabang + "'";
        ResultSet res = null;
        try {
            res = stat.executeQuery(que1);
        } catch (SQLException ex) {
            Logger.getLogger(CekStokBarangPusat.class.getName()).log(Level.SEVERE, null, ex);
        }
        return res;
    }

    public void updateStokCabang(String jum, String kode, String idcabang) throws SQLException {
        Connection con = DataBase.Koneksi.open(); 
        Statement sta = con.createStatement();
        ResultSet rst = sta.executeQuery("select * from stockbarangcabang_frogstone where id_cabang='"
                +idcabang+"' and kodebarang='"+kode+"'");
        String stok=null;
        while(rst.next()){
            stok=rst.getString("jumlahbarang");
        }
        int jum1 = Integer.parseInt(stok) + Integer.parseInt(jum);
        String jumlah = String.valueOf(jum1);
        String sql = "update STOCKBARANGCABANG_FROGSTONE set JUMLAHBARANG='" + jumlah
                + "' where KODEBARANG='" + kode + "' and ID_CABANG='" + idcabang + "'";
        sta.executeUpdate(sql);
    }
}
